#pragma once

#include <vector>

#include "cork.h"

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <emscripten/bind.h>
#include <emscripten/val.h>
#endif

using Handle = size_t;

namespace MeshProcessing {
	class PMesh : public CorkTriMesh {

	public:
		PMesh();

		PMesh(uint numVertices, float* v, uint numIndices, uint* i);

		virtual ~PMesh();

		void preprocessMesh(bool bRemoveDegenerate);

		uint getNumVertices();
		uint getNumIndices();

		uint* getIndices();
		float* getVertices();

		void setVertices(uint numVertices, float* in);
		void setIndices(uint numIndices, uint* in);

#ifdef __EMSCRIPTEN__
		emscripten::val getIndexArray();
		emscripten::val getVetexArray();
		void addVertices(emscripten::val);
		void addTriangles(emscripten::val);
#else
		void addVertices(uint numVertices, float* in);
		void addTriangles(uint numIndices, uint* in);
#endif

		void destroyMesh();

		Handle toHandle();

		void update();

	private:
		bool m_bPreprocess = false;

		void initializeTriMesh();

	private:
		std::vector<double> m_tempVertexData;
		std::vector<uint> m_tempIndexData;
	};
}
